﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyMvc.IDAL;
using MyMvc.IBLL;
using MyMvc.Model.Models;
using MyMvc.DAL;
using MyMvc.Model;

namespace MyMvc.BLL
{
    public partial class UserService : BaseService<User>, IUserService
    {
        /// <summary>
        /// 检验用户是否登录成功
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public User checkUserLogin(User userinfo)
        {
            //判断用户的用户名密码是否正确
            return _dbSession.UserRepository.LoadEntities(u => u.UserName == userinfo.UserName && u.PassWord == userinfo.PassWord)
                .FirstOrDefault();
        }


        public IQueryable<User> LoadSearchData(GetModelQuery query)
        {
            //拿到所有数据
            var temp = _dbSession.UserRepository.LoadEntities(u => true);
            query.total = temp.Count();
            return temp.Skip(query.pageSize * (query.pageIndex - 1)).Take(query.pageSize).AsQueryable();
        }

        /// <summary>
        /// List集合实现多选删除数据
        /// </summary>
        /// <param name="DeleteUserInfoID"></param>
        /// <returns></returns>
        public int DeleteUserInfo(List<int> DeleteUserInfoID)
        {
            foreach (var ID in DeleteUserInfoID)
            {
                _dbSession.UserRepository.DeleteEntities(new User() { ID = ID });
            }
            return _dbSession.SaveChanges();
        }
    }

}
